//
//  ShopCarLastView.m
//  EasyToTesco2.0
//
//  Created by 袖手旁觀 on 16/8/1.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "ShopCarLastView.h"

@implementation ShopCarLastView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
     
        [self addLastViewUI];
        
    }
    return self;
}

- (void)addLastViewUI {
    UIView *topLine = [[UIView alloc] init];
    topLine.backgroundColor = [UIColor blackColor];
    topLine.alpha = 0.1;
    [self addSubview:topLine];
    
    [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.top.equalTo(self.mas_top);
        make.width.mas_equalTo(WIDTH);
        make.height.mas_equalTo(1);
    }];
    
    UIView *bottomLine = [[UIView alloc] init];
    bottomLine.backgroundColor = [UIColor blackColor];
    bottomLine.alpha = 0.1;
    [self addSubview:bottomLine];
 
    [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom);
        make.left.equalTo(self.mas_left);
        make.width.mas_equalTo(WIDTH);
        make.height.mas_equalTo(1);
    }];
    
    UIButton *chooseButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [chooseButton setImage:[UIImage imageNamed:@"gouwuche_2"] forState:UIControlStateNormal];
    [chooseButton setImage:[UIImage imageNamed:@"gouwuche_0"] forState:UIControlStateSelected];
    [chooseButton setTitle:@"全选" forState:UIControlStateNormal];
    [chooseButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [chooseButton addTarget:self action:@selector(didClickAllChooseButton:) forControlEvents:UIControlEventTouchUpInside];
    chooseButton.titleLabel.font = [UIFont systemFontOfSize:16];
    chooseButton.imageView.contentMode = UIViewContentModeScaleToFill;
    [chooseButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 10)];
//    chooseButton.backgroundColor = [UIColor orangeColor];
    self.chooseButton = chooseButton;
    [self addSubview:chooseButton];
    
    [chooseButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.top.equalTo(self.mas_top);
        make.height.mas_equalTo(self.Height);
        make.width.mas_equalTo(self.width * 0.2);
    }];
    
    UIButton *accountButton = [[UIButton alloc] init];
    [accountButton setTitle:@"结算" forState:UIControlStateNormal];
    accountButton.layer.cornerRadius = 3;
    accountButton.layer.masksToBounds = YES;
    accountButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [accountButton addTarget:self action:@selector(didClickAccountButton:) forControlEvents:UIControlEventTouchUpInside];
    [accountButton setBackgroundColor:DEFAULT_COLOR];
    [self addSubview:accountButton];
    self.accountButton = accountButton;
    
    [accountButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).with.offset(-6);
        make.top.equalTo(self.mas_top).with.offset(4);
        make.height.mas_equalTo(self.Height - 8);
        make.width.mas_equalTo(WIDTH * 0.25 - 16);
    }];
    
    UILabel *noFreightLabel = [[UILabel alloc] init];
    noFreightLabel.text = @"不含运费";
//    noFreightLabel.backgroundColor = [UIColor orangeColor];
    noFreightLabel.textAlignment = NSTextAlignmentCenter;
    noFreightLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:noFreightLabel];
    self.noFreightLabel = noFreightLabel;
    
    [noFreightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.right.equalTo(accountButton.mas_left).with.offset(-8);
        if(iPhone5) {
            make.width.mas_equalTo(WIDTH * 0.2);
        } else {
            make.width.mas_equalTo(WIDTH * 0.15);
        }
        make.height.mas_equalTo(self.mas_height);
    }];
    
    UILabel *priceLabel = [[UILabel alloc] init];
    priceLabel.text = @"合计:¥0.00";
    if (iPhone5) {
        priceLabel.font = [UIFont systemFontOfSize:13];
    } else {
        priceLabel.font = [UIFont systemFontOfSize:15];
    }
    priceLabel.textColor = DEFAULT_COLOR;
    priceLabel.textAlignment = NSTextAlignmentLeft;
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:priceLabel.text];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,2)];
    priceLabel.attributedText = str;
    [self addSubview:priceLabel];
    self.priceLabel = priceLabel;
    
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(chooseButton.mas_right).with.offset(8);
        make.right.equalTo(accountButton.mas_left);
        make.top.equalTo(self.mas_top);
        make.bottom.equalTo(self.mas_bottom);
    }];
}
/**
 *  全选按钮
 */
- (void)didClickAllChooseButton:(UIButton *)chooseButton{
    chooseButton.selected = !chooseButton.selected;
}

/**
 *  结算按钮
 */
- (void)didClickAccountButton:(UIButton *)accountButton {
    
}

@end
